#ifndef CVIMAGEHTTP_H
#define CVIMAGEHTTP_H

#include <QObject>
#include <QUrl>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QSslError>
#include <QtNetwork/QNetworkCookie>
#include <QByteArray>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptValue>
#include <QList>
#include <QTextCodec>
#include <QImageReader>
#include <QImage>
#include <QPixmap>

#include "bizlogic/cvimagecache.h"

class CVImageHttp : public QObject
{
    Q_OBJECT
public:
    CVImageHttp(QUrl url);

    void setDefaultImage(QImage *image);
signals:
    void handleImage(QPixmap pixmap);
public slots:
    void readyReadSlot();
    void downloadProgressSlot(qint64 bytesReceived, qint64 total);
    void finishedSlot();
    void errorSlot(QNetworkReply::NetworkError error);
private slots:
    void ignoreSslError(QNetworkReply *reply, QList<QSslError> error);
private:
    void init();
    void initSlots();   

    QUrl mUrl;
    QImage *defaultImage;

    QNetworkAccessManager *manager;
    QNetworkReply *reply;
};

#endif // CVIMAGEHTTP_H
